<?php

$hostname = 'mysql5.000webhost.com';
$username = 'a8665889_khron';
$password = 'hahaha:)';
$dbname = 'a8665889_tek';

///*
$hostname = 'localhost';
$username = 'root';
$password = 'root';
$dbname = 'tek_ro';
//update jos_sliced_anatomica_part, jos_sliced_anatomica3 set name_ro=name_ro_par, email=email_par where nomina=nomina_par
//*/


$q = strtolower($_GET["q"]);
$key = $_GET["key"];
$langs = $_GET["nomina"];
if ($q) show_items($q);
if ($key) show_item($key);

function show_items($q){
	global $hostname,$username,$password,$dbname,$langs;
	$dbh = new mysqli($hostname, $username, $password, $dbname);
	$where = "0 ";
	if (strpos($langs,"na") === false) $where = "0 "; else {
		$where = $where . ' or nomina like "%'.$q.'%"';
	}	
	if (strpos($langs,"en")) $where = $where . ' or name_en like "%'.$q.'%"';
	if (strpos($langs,"ro")) $where = $where . ' or name_ro like "%'.$q.'%"';
	$sql = 'select * from `jos_sliced_anatomica3` WHERE  '.$where.' limit 0,30';
	//print $sql;

	$items=array();
	if ($res = $dbh->query($sql)) {
		while($r=$res->fetch_object()) {
	    	if ($r->id) {
				$item = $r->nomina." / ".$r->name_en." / ".$r->name_ro."|".$r->id;
				array_push($items, $item);
			}
		}
	} else {
		printf("There has been an error from MySQL: %s",$dbh->error);
	}
	$res->close();
	$dbh->close();


	foreach ($items as $key=>$value) {
	
			echo "$value\n";
	
	}
}

function show_item($key) {
	global $hostname,$username,$password,$dbname;
	$dbh = new mysqli($hostname, $username, $password, $dbname);
	$sql = 'select * from `jos_sliced_anatomica3` WHERE id='.$key;

	$items=array();
	if ($res = $dbh->query($sql)) {
		while($r=$res->fetch_object()) {
	    	if ($r->id) {
				$item = $r->nomina." | ".$r->name_en."|".$r->description_en." | ".$r->name_ro."|".$r->description_ro."|".$r->id."|".$r->email;
				array_push($items, $item);
				echo $item;
			}
		}
	} else {
		printf("There has been an error from MySQL: %s",$dbh->error);
	}
	$res->close();
	$dbh->close();
	
}

?>